# Agent Packing Script
# Usage: .\pack_en.ps1

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Agent Project Packing" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir

if (-not (Test-Path "main.py")) {
    Write-Host "Error: main.py not found!" -ForegroundColor Red
    exit 1
}

if (Test-Path "agent.tar.gz") {
    Write-Host "Removing old archive..." -ForegroundColor Yellow
    Remove-Item "agent.tar.gz" -Force
}

Write-Host "Packing files..." -ForegroundColor Blue

tar -czf agent.tar.gz --exclude=__pycache__ --exclude=*.pyc --exclude=logs --exclude=screenshots --exclude=.git --exclude=state.json --exclude=agent.tar.gz --exclude=pack_agent.sh --exclude=pack_agent.ps1 --exclude=pack_simple.ps1 --exclude=pack_en.ps1 *

if ($LASTEXITCODE -eq 0) {
    $fileSize = (Get-Item "agent.tar.gz").Length / 1MB
    $fileSizeMB = [math]::Round($fileSize, 2)
    
    Write-Host ""
    Write-Host "Success!" -ForegroundColor Green
    Write-Host "  File: agent.tar.gz" -ForegroundColor Green
    Write-Host "  Size: $fileSizeMB MB" -ForegroundColor Green
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Cyan
    Write-Host "Next Steps:" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "1. Upload to control server:" -ForegroundColor Blue
    Write-Host "   scp agent.tar.gz root@your-server:/tmp/" -ForegroundColor Gray
    Write-Host ""
    Write-Host "2. Deploy via admin panel:" -ForegroundColor Blue
    Write-Host "   - Go to [Server Management] menu" -ForegroundColor Gray
    Write-Host "   - Select servers to deploy" -ForegroundColor Gray
    Write-Host "   - Click [Batch Deploy Agent] button" -ForegroundColor Gray
    Write-Host "   - Enter file path: /tmp/agent.tar.gz" -ForegroundColor Gray
    Write-Host "   - Start deployment" -ForegroundColor Gray
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Cyan
} else {
    Write-Host "Packing failed!" -ForegroundColor Red
    Write-Host "Error code: $LASTEXITCODE" -ForegroundColor Red
    exit 1
}

